package it.storm.solution;

/**
 * 1700. 无法吃午餐的学生数量
 * https://leetcode-cn.com/problems/number-of-students-unable-to-eat-lunch/
 */
public class Solutions_1700 {
    public static void main(String[] args) {
        int[] students = {1, 1, 0, 0}, sandwiches = {0, 1, 0, 1};  // output: 0
//        int[] students = {1, 1, 1, 0, 0, 1}, sandwiches = {1, 0, 0, 0, 1, 1};  // output: 3

        int result = countStudents(students, sandwiches);
        System.out.println(result);
    }

    public static int countStudents(int[] students, int[] sandwiches) {
        // arr[0] = 3：3 位学生吃圆形三明治
        int[] arr = new int[2];
        for (int student : students) {
            arr[student] ++;
        }
        for (int i = 0; i < sandwiches.length; i++) {
            int j = sandwiches[i];
            if (arr[j] < 1) {
                // 剩下的学生无法吃到
                return sandwiches.length - i;
            }
            arr[j] --;
        }
        return 0;
    }
}
